from matplotlib import pyplot as plt
import matplotlib,csv
reader=csv.reader(open("../Trending YouTube Video Statistics/dataset/USvideos.csv","r",encoding="utf-8"))
matplotlib.rcParams['font.sans-serif']=['SimHei']   # 用黑体显示中文
matplotlib.rcParams['axes.unicode_minus']=False     # 正常显示负号
view,like,dislike,comment_count=[],[],[],[]
for row in reader:
    view.append(row[7]) #索引表示所在列
    like.append(row[8])
    dislike.append(row[9])
    comment_count.append(row[10])
view=[int(view[i]) for i in range(1,len(view))]
like=[int(like[i]) for i in range(1,len(like))]
dislike=[int(dislike[i]) for i in range(1,len(dislike))]
comment_count=[int(comment_count[i]) for i in range(1,len(comment_count))]
print(len(view),len(like),len(dislike),len(comment_count))
def histogram(datas,xlabel,title):
    plt.ticklabel_format(style="plain")
    plt.hist(datas)
    plt.xlabel(xlabel)
    plt.ylabel("频数")
    plt.title(title)
    plt.show()
def box(datas,title):
    plt.ticklabel_format(style="plain")
    plt.title(title)
    plt.boxplot(datas,showmeans=True,showfliers=False)
    plt.show()
histogram(view,"播放量","播放量view直方图")
histogram(like,"喜欢","喜欢like直方图")
histogram(dislike,"不喜欢","不喜欢dislike直方图")
histogram(comment_count,"评论数量","评论数量comment_count直方图")
box(view,"播放量view盒图")
box(like,"喜欢like盒图")
box(dislike,"不喜欢dislike盒图")
box(comment_count,"评论数量comment_count盒图")